<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :span="5">
            <a-form-item :label="$t('设备类型')">
              <a-select v-model="queryParam.deviceType">
                <a-select-option :value="item.value" :key="index" v-for="(item, index) in devicetypeList"
                  >{{ item.title }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item :label="$t('设备名称(编码)')">
              <a-select show-search :filter-option="false" @search="handleSearch" v-model="queryParam.deviceId">
                  <a-select-option :value="item.id" :key="index" v-for="(item, index) in deviceList">
                    <span>{{ item.name }}</span>
                    <span v-if="item.name != $t('全部')">({{ item.id }})</span>
                  </a-select-option>
                </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="5">
            <a-form-item :label="$t('操作员')">
              <a-select v-model="queryParam.operator">
                <a-select-option v-for="(item, index) in userList" :value="item.id" :key="index">{{
                  item.realname
                }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <span style="float: left; overflow: hidden; margin-left: 8px" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('查询')}}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('重置')}}</a-button>
            </span>
          </a-col>
          <template v-if="toggleSearchStatus">
          </template>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a v-has="'BisCheckOutController:checkout'" @click="handleDetail(record)">{{$t('结账')}}</a>
        </span>
      </a-table>
    </div>
    <un-check-out-detailt-modal ref="modalForm" @ok="modalFormOk"></un-check-out-detailt-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { getAction } from '@/api/manage'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
import UnCheckOutDetailtModal from './modules/UnCheckOutDetailtModal'

export default {
  name: 'EquipmentUnCheckOut',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    UnCheckOutDetailtModal,
  },
  data() {
    return {
      description: '设备未结账记录',
      // 表头
      columns: [
        {
          title: this.$t('设备编码'),
          align: 'center',
          dataIndex: 'deviceId',
        },
        {
          title: this.$t('设备名称'),
          align: 'center',
          dataIndex: 'deviceName',
        },
        {
          title: this.$t('设备类型'),
          align: 'center',
          dataIndex: 'deviceType_dictText',
        },
        {
          title: this.$t('操作员'),
          align: 'center',
          dataIndex: 'operator',
        },
        {
          title: this.$t('账目开始时间'),
          align: 'center',
          dataIndex: 'startTime',
        },
        {
          title: this.$t('操作'),
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/checkout/notCheckOut/list',
      },
      dictOptions: {},
      deviceList: [],
      userList: [],
      devicetypeList: [],
      queryParam: {
        deviceId: '',
        operator: '',
        deviceType: '',
      },
      isCustom:true,
      isHideData:false
    }
  },
  created() {},
  mounted(){
    let that=this
    document.onkeydown = function(e) {
      let key = window.event.keyCode;
      if (key== 75 && event.ctrlKey) {
        window.event.preventDefault()
        that.$refs.modalForm.visible=false
        that.isHideData = false
        that.queryParam.dataType=0
        that.searchQuery()
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {
      initDictOptions('bis_device_info.type').then((res) => {
        if (res.success) {
          this.devicetypeList = res.result
          this.devicetypeList.unshift({ title: this.$t('全部'), value: '' })
        }
      })
      getAction('/sys/user/list',{ pageSize : 999 }).then((res) => {
        if (res.success) {
          this.userList = res.result.records
          this.userList.forEach(col => {
            col.id = col.realname
          });
          this.userList.unshift({ id: '', realname: this.$t('全部') })
        }
      })
      this.customInit()
    },
    customInit() {
      this.handleSearch('')
      this.isHideData = true
      this.queryParam.dataType=1
      this.loadData(1)
    },
    handleSearch(value) {
      let query={}
      if(value){
        query.deviceInfo= value
      }
      getAction('/device/bisDeviceInfo/list',query).then((res) => {
        if (res.success) {
          this.deviceList = res.result.records
          this.deviceList.unshift({ id: '', name: this.$t('全部') })
        }
      })
    },
    searchReset() {
      this.handleSearch('')
      this.queryParam = {
        deviceType:'',
        deviceId: '',
        operator: ''
      }
      this.customInit()
    },
    handleDetail(record){
      let dtl=Object.assign({},record,{dataType:this.queryParam.dataType})
      this.$refs.modalForm.edit(dtl);
      this.$refs.modalForm.title=this.$t('详情');
      this.$refs.modalForm.disableSubmit = true;
    }
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>